/* eslint-disable no-mixed-operators */
import React from 'react';
import {Button} from 'antd';
import {formatMessage} from './intl';
import routes from './routes';
import ExcelImportIntl from '../common/ExcelImportIntl';
import PropTypes from 'prop-types';
const basePath = fetch.basePath || '';

class ImportProducAttributes extends React.PureComponent {
    constructor(props) {
        super(props);
        this.state = {
            loading: false
        };
    }
    beforeUpload = () => this.setState({loading: true});

    afterUpload = () => this.setState({loading: false});

    render() {
        const description = [
            formatMessage({
                id: 'importProduceAttributes.step2.description1',
                defaultMessage: '备件编号需有效且不可重复'
            }),
        ];

        return ([
            <div key="return" className="page-toolbar">
                <Button type="primary" href={`#${routes.query.url()}`} disabled={this.state.loading}>
                    {formatMessage({
                        id: 'importProduceAttributes.btm.return',
                        defaultMessage: '返回'
                    })}
                </Button>
            </div>,
            <ExcelImportIntl
                key="import"
                template={this.props.produceAttributesImportTemp}
                templateName={formatMessage({
                    id: 'produceAttributes.excelImportIntl.templateName',
                    defaultMessage: '生产信息导入模板'
                })}
                action={`${basePath}/parts/api/v1/parts/produceAttributes/import`}
                description={description}
                beforeUpload={this.beforeUpload}
                afterUpload={this.afterUpload}/>
        ]);
    }
}

ImportProducAttributes.propTypes = {
    produceAttributesImportTemp: PropTypes.func,
};

import {connect} from 'react-redux';
import {
    produceAttributesImportTemp
} from './actions';
const mapDispatchToProps = dispatch => ({
    produceAttributesImportTemp: () => dispatch(produceAttributesImportTemp())
});
export default connect(null, mapDispatchToProps)(ImportProducAttributes);
